#include ("/_includes/_layout.html")
#define css()
<link rel="stylesheet" type="text/css" href="#(webctx)/resources/css/product.css"/>
<link rel="stylesheet" type="text/css" href="#(webctx)/resources/js/map/AMap.PlaceSearchRender1120.css"/>
<style type="text/css">
.col-md-5 select{
	width: 30%;
	float: left;
}
</style>
#end
#define script()
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.6&key=d418a8a1e6d51110dd5f0390662943c0&plugin=AMap.PlaceSearch"></script>
<script type="text/javascript" src="#(webctx)/resources/js/map/PlaceSearchRender.js"></script>
<script type="text/javascript" src="#(webctx)/resources/js/jquery.lSelect.js"></script>
<script type="text/javascript">

function addPictureSign(obj){
	obz.selectImageOne(function(selImgs){
		if(selImgs.length<=0){
			obz.error("请选择一张图片");
			return false;
		}
		var img = selImgs[0];
		
		var h='<img class="image-preview" src="'+img.url+'" >';
        h=h+'<a class="close-modal small hide" href="javascript:;" onclick="deleteSignImg();">×</a>';
	    $("#shopSign-image-div").empty().append(h); 
	    $('#sowing_img').val(img.title);
		return true;
	});
}

function deleteSignImg(){
	 var h='<a class="main-image-add" onclick="addPictureSign(true);" href="javascript:;">+加图</a>';
	 $("#shopSign-image-div").empty().append(h);
	 $('#sowing_img').val('');  
}
</script>
#end
#@layout("店铺管理", "wxmall,点步科技", "Wxmall社区","wxmall")
#define content()
<div class="wrapper wrapper-content">
	<div class="ibox-content">
		<form id="shopForm" class="form-horizontal" >
			<div>
				<input type="hidden" id="id" name="id" value="#(sowing.id??)"/>
				
				<div class="form-group">
		            <label class="col-md-2 control-label">地址<span style="color: red;"><em>*</em></span></label>
		            <div class="col-md-4" id="error_shop_name">
		                <input type="text" id="sowing_url" name="sowing_url" class="form-control"  value="#(sowing.sowingUrl??)"/>
		                <label class="control-label" for="sowing_url"></label>
		                 <p class="size-remark">选择地址按钮用于小程序方便选择要跳转的地址,公众号需要手动输入地址 </p>
		            </div>
		            
					<div class="btn-group">
					  <button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
					    选择地址 <span class="caret"></span>
					  </button>
					  <!-- <i class="fa fa-question-circle" onmouseout="layer.closeAll();" onmouseover="layer.tips('用于小程序选择地址<br/>公众号自己输入', this, {tips: [1, '#3595CC'],time: 0});"></i> -->
					  <ul class="dropdown-menu">
					  	#for(page: pageList??)
					    <li><a class="active-a" href="javascript:void(0)">#(page)</a></li>
					     #end
					  </ul>
					</div>
		          
		        </div>
		         
		        
		       <!--  #if(appid == 10)
		        <div class="form-group">
		            <label class="col-md-2 control-label">跳转地址<span style="color: red;"><em>*</em></span></label>
		            <div class="col-md-4" id="error_shop_name">
		                <input type="text" id="sowing_url" name="sowing_url" class="form-control"  value="#(sowing.sowingUrl??)"/>
		                <label class="control-label" for="sowing_url"></label>
		                </div>
		         </div>
		        #else
		         <div class="form-group">
		        	<label class="col-md-2 control-label">选择地址&nbsp;&nbsp;</label>
		        	<div class="col-md-8">
			            <select id="sowing_url" name="sowing_url" class="control-inline disabled-input">
							
							<option value="#(sowing.sowingUrl??'pages/index/index')" selected="selected">#(sowing.sowingUrl??'pages/index/index')</option>
							<option value="pages/cart/cart">pages/cart/cart</option>
							
							#for(page: pageList??)
								#if(page == sowing.sowingUrl??)
									<option value="#(page)" selected="selected">#(page)</option>
								#else
									<option value="#(page)">#(page)</option>
								#end
							 #end
						</select>
						<div class="replace-scope" style="display: inline-block; margin-top: 10px; color: gray;"><span></span></div>
					</div>
		        </div>
		        #end -->
		       
		        <div class="form-group">
		            <label class="col-md-2 control-label">轮播图<span style="color: red;"><em></em></span></label>
		            <div class="col-md-4" >
		                <input id="sowing_img" name="sowing_img" value="#(sowing.sowingImg??)" type="hidden">
					     <div id="shopSign-image-div" class="main-image-div">
                                  #if(sowing.sowingImg??)
                                    <img class="image-preview" src="#(img_domain)#(sowing.sowingImg??)" >
                                       <a class="close-modal small hide" href="javascript:;" onclick="deleteSignImg();">×</a>
                                  #else 
				                <a class="main-image-add" onclick="addPictureSign(true);" href="javascript:;" >+加图</a>
				             	  #end
				           </div>

					       <p class="size-remark">小程序首页轮播图建议尺寸：320*162像素 </p>
		            </div>
		        </div>
		        
		        <div class="form-group">
		            <div class="col-md-6" align="right">
		                <button type="submit" class="btn btn-success btn-sm">保 存</button>
		                <a href="#(webctx)/sowingimg" class="btn btn-white btn-sm" type="reset">取消</a>
		            </div>
		        </div>
			</div>
			
	  	</form>
  	</div>
</div>
#end
<script type="text/javascript">


$(document).ready(function() {
	
	 $(".active-a").on(
       "click",
       function(e) {
           $("#sowing_url").val(e.target.innerHTML);
       });  
	//----
	$(".main-image-div").hover(function(){
		$(this).find(".close-modal").removeClass("hide");
	   $(this).find(".close-modal").addClass("hover");
	},function(){
		 $(this).find(".close-modal").addClass("hide");  
		 $(this).find(".close-modal").removeClass("hover");
	});
	
	// validate signup form on keyup and submit
	var icon = "<i class='fa fa-times-circle'></i> ";
    $("#shopForm").validate({
    	ignore: "",
    	errorElement: "em",
        submitHandler:function() {
        	$("#shopForm").mask("正在保存...");
        	var params = $("#shopForm").serializeJSON();
        	obz.ajaxJson(obz.ctx+"/shop/saveSowing", params, function(json) {
        		
        		$("#shopForm").unmask();
    			if(json.code!=200){
    				obz.error(json.msg);
    			}else{
    				obz.msg('保存成功', function(){
    					location.href = "#(webctx)/shop/sowingimage";
    				});					
    			}
    		});
        },
        rules: {
        	sowing_img: "required", 
        	//sowing_url: "required"
        },
        messages: {
        	sowing_img: icon + "请上传店铺轮播图",
        	//sowing_url: icon + "请输入轮播图对应的地址", 
        	
        }
    });
});
</script>